/*This program takes in a text file containing city names and various statistics about the cities.  It than reads the cities
line by line and assigns the stats and city name to various variables for use in determining the best city to live in.
It than outputs each city's population density and livability rating and which city is the best to live in.
*/

//includes my header
#include "stdafx.h"

void main(){
	
	//input file pointer
	FILE *ifp;
	
	//string variable for the current city
	char city [30];
	
	//string variable for best city
	char BestCity[31];
	
	//input file int variables for city stats
	int pop , sqMil , pollu, crime, expense, highway;
	
	//used as a halt function for scanf to keep the console window open
	int n = 0;
	
	//calculation variables
	double PopDens, PolluAmt, TrafficRating, CrimePerCap, ExpensePerCap, Livability, BestRating;
	
	// counts the number of cities based o
	int count = 0;
	
	//opens input file
	ifp = fopen("city1.txt", "r");
	
	//sets up the first line in the console window
	FirstPrint();
	
	//passes the input file and the variables to Input() and loops until Input() returns -1
	while(Input(ifp, city, &pop, &sqMil , &pollu, &crime, &expense, &highway ) != -1){
		
		//calculates the population density by passing in the population and square mileage
		PopDensCalc(pop, sqMil, &PopDens);
		
		//passes the city stats and calculation variables to Calculations()
		Calculations(pop, sqMil , pollu, crime, expense, highway, PopDens, 
			&PolluAmt, &TrafficRating, &CrimePerCap, &ExpensePerCap);
	
		//calculates the best city by passing in the variables from the calculations function and storage variables for determining the best city
		LivabilityCalc(city , BestCity, PolluAmt, TrafficRating, CrimePerCap, ExpensePerCap, &Livability, &BestRating);
		
		//increments the city counter
		count ++;
		
		//calls Output pass in calculated variables to print to the console
		Output(city , PopDens, Livability);
	
	}
	
	//prints the best city and its rating
	FinalPrint(BestCity, count, BestRating);
	
	//halts the console window until user input is detected
	scanf("%d", &n);
	
	//close the input file
	fclose(ifp);
	
}//end main